home *** CD-ROM | disk | FTP | other *** search
/ Quick PC 61 / Quick PC 61.iso / I386 / SASETUP.MSI / F77692_Text_Log_download.asp < prev    next >
Encoding:
Text File  |  2003-02-21  |  6.5 KB  |  214 lines

  1. <%@ Language=VBScript        %>
  2. <%    Option Explicit            %>
  3. <%    Response.Buffer = True
  4.     '-------------------------------------------------------------------------
  5.     ' Text_log_download.asp: to download the log files of type text
  6.     '
  7.     ' NOTE: This is a customized page written to take care of the "Downloading"
  8.     ' of the log(text) files. 
  9.     ' This is not the types of the pages(area, property, etc) of the framework.
  10.     ' Hence, the events applicable to those is not used  here.
  11.     '
  12.     ' Copyright (c) Microsoft Corporation.  All rights reserved. 
  13.     '-------------------------------------------------------------------------
  14.     Call SAI_EnablePageCaching(TRUE)
  15. %>
  16.     <!-- #include virtual="/admin/inc_framework.asp" --> 
  17.     <!-- #include file="loc_Log.asp" -->
  18.     <!-- #include file="inc_Log.asp" -->
  19. <%
  20.     Dim F_strFile            'File name with file path
  21.     Dim F_strFileName        'File name to be prompted for download    - Example: nfssvr.txt
  22.     Dim F_strDownloadClick    'variable to get selected radio button value 
  23.     Dim blnFlagIE 
  24.     
  25.     F_strDownloadClick = Request.Form("downloadclicked") 
  26.  
  27.     If SA_IsIE = True Then
  28.         blnFlagIE = True 
  29.     End If
  30.     
  31.     'select case for download 
  32.     Select Case F_strDownloadClick
  33.         Case "True"
  34.             Call DownLoadLog()
  35.         case else
  36.             Call ServePage()
  37.     End Select
  38.     
  39.     '---------------------------------------------------------------------
  40.     ' Function name:    DownLoadLog
  41.     ' Description:        Downloads the file
  42.     ' Input Variables:    None
  43.     ' Output Variables:    None
  44.     ' Return Values:    None
  45.     ' Global Variables: F_strFileName,F_strFile,L_LOGFILE_NOTFOUND_ERRORMESSAGE
  46.     'Called to read the total content of the file and output it.
  47.     'Due to the headers, the "download" dialog appears
  48.     '---------------------------------------------------------------------
  49.     Function DownLoadLog()
  50.         On error resume next
  51.         Err.Clear
  52.     
  53.         'File name(along with the path) that is obtained from earlier form
  54.         F_strFile  = Request.QueryString("FilePath")
  55.         F_strFileName = Mid(F_strFile,instrRev(F_strFile, "\") + 1)
  56.         
  57.         'Check if the file is existing
  58.         If Not (isFileExisting(F_strFile)) Then
  59.             'File is moved/deleted/renamed. Display failure page
  60.             Call SA_TraceOut("Text_Log_Download.asp", "File does not exist.")
  61.             Exit function
  62.         End If    
  63.  
  64.         'Call to output the log file
  65.         If not ReadDisplayFileContent(F_strFile,F_strFileName) then
  66.             Exit function
  67.         End if
  68.     End function
  69.     
  70.     '---------------------------------------------------------------------
  71.     ' Function name:    ReadDisplayFileContent
  72.     ' Description:        To Read and Output the contents of the file
  73.     ' Input Variables:    The file to be read and displayed
  74.     ' Output Variables:    None
  75.     ' Return Values:    None
  76.     ' Global Variables: None
  77.     'Called to read the total content of the file and output it.
  78.     'For Netscape the headers are not added location.href is used
  79.     'Due to the headers, the "download" dialog appears
  80.     '---------------------------------------------------------------------
  81.     Function ReadDisplayFileContent(strFilePath , strFileName)
  82.         On error resume next
  83.         Err.Clear
  84.         
  85.         Dim objFSO
  86.         Dim objFile    ' the File to be read
  87.         Dim strTemp
  88.         Dim strLogPath
  89.         Dim strDownloadFile
  90.                     
  91.         const TempDir = "TempFiles"    ' A Temporary directory in web directory
  92.         const LogDir = "LogFiles" ' A logs directory in Temporary directory
  93.         const strON    = "On"
  94.  
  95.         Dim oEncoder
  96.         Set oEncoder = new CSAEncoder
  97.         
  98.         ReadDisplayFileContent = true
  99.         
  100.         ' Add headers to download the log file
  101.         Call SA_TraceOut("Text_Log_Download.asp", "strFileName: " + strFileName)
  102.         Call SA_TraceOut("Text_Log_Download.asp", "strFilePath: " + strFilePath)
  103.         
  104.         Set objFSO = CreateObject("Scripting.FileSystemObject")
  105.         If Err.number <> 0 then 
  106.             ReadDisplayFileContent = false
  107.             Exit function
  108.         End If
  109.  
  110.         If blnFlagIE = True then 
  111.             Set objFile = objFSO.OpenTextFile(strFilePath, 1)
  112.             'Read the contents of the file
  113.             If not objFile.AtEndOfStream Then strTemp = objFile.readall End IF
  114.             
  115.             objFile.Close
  116.             Set objFile = Nothing
  117.             
  118.             ' Add headers for text log download
  119.             Response.AddHeader "Content-Type", "text/plain"
  120.             Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName
  121.  
  122.             'Clear any previous buffered output
  123.             Response.Clear
  124.  
  125.             'Output it for download
  126.             Response.Write(oEncoder.EncodeElement(strTemp))
  127.         
  128.             Response.Flush
  129.         Else
  130.             strLogPath = GetLogsDirectoryPath(objFSO)
  131.             
  132.             If objFSO.FileExists(strLogPath& "\" &strFileName) then
  133.                 objFSO.DeleteFile strLogPath& "\" &strFileName,True
  134.             End If
  135.             
  136.             ' Copying from log's original directory to web root
  137.             If objFSO.FileExists(strFilePath) Then
  138.                 objFSO.CopyFile strFilePath, strLogPath& "\" ,True
  139.             End If
  140.             
  141.             'Clean up
  142.             Set objFSO  = Nothing
  143.             
  144.             strDownloadFile = SA_GetNewHostURLBase(SA_DEFAULT, SAI_GetSecurePort(), True, SA_DEFAULT)
  145.             strDownloadFile = strDownloadFile & TempDir &"/" &LogDir &"/" & strFileName
  146.             Call SA_TraceOut("SINGLELOGS" , "log file=" & strDownloadFile)    
  147.  
  148.             Call ServePage()
  149.         %>
  150.             <script language="javascript">
  151.                 top.location.href = '<%=strDownloadFile%>';
  152.             </script>
  153.         <%
  154.         End If    
  155.  
  156.         Set oEncoder = Nothing
  157.         Set objFSO = Nothing
  158.         
  159.     End function
  160.     
  161.     '---------------------------------------------------------------------
  162.     ' Function name:    ServePage
  163.     ' Description:        Serve the contents to the page
  164.     ' Input Variables:    None
  165.     ' Output Variables:    None
  166.     ' Return Values:    None
  167.     ' Global Variables: None
  168.     ' Submit(Download) button is displayed and on click of it the download 
  169.     ' Functionality is processed
  170.     '---------------------------------------------------------------------
  171.     Sub ServePage
  172.     %>
  173.     
  174.     <html>
  175.     <head>
  176.         <link rel="STYLESHEET" type="text/css" href="<%=m_VirtualRoot%>style/mssastyles.css">
  177.     </head>
  178.     <body>
  179.     <form id=sa_formdownload name=sa_formdownload method="POST" target="_self">
  180.         <input name="<%=SAI_FLD_PAGEKEY%>" type="hidden" value="<%=SAI_GetPageKey()%>">
  181.         <table border="0" cellspacing="0"  cellpadding="0">
  182.             <tr>
  183.                 <td class="TasksBody">
  184.                 <%
  185.                 Call SA_ServeOnClickButton(SA_EscapeQuotes(Trim(L_DOWNLOAD_TEXT)), "",_
  186.                                "SubmitLog()",_
  187.                                 90,"", "" )        
  188.                 %>                
  189.                     <input type=hidden name=downloadclicked id=downloadclicked value="">
  190.                 </td>
  191.             </tr>
  192.         </table>
  193.     </form>
  194.     </body>
  195.     </html>
  196.     <script language="JavaScript">
  197.         function SubmitLog()
  198.         {
  199.             var oException;
  200.             try
  201.             {
  202.                 document.sa_formdownload.downloadclicked.value = "True";
  203.                 document.sa_formdownload.submit();
  204.             }
  205.             catch(oException)
  206.             {
  207.             }
  208.         }
  209.     </script>
  210.     <%
  211.     End Sub
  212.  
  213. %>
  214.